
{extend name='../../admin/view/table'}

{block name="button"}
<button data-modal='{:url("add")}' data-offset="20" data-title="添加品种" class='layui-btn layui-btn-sm layui-btn-primary'>添加品种</button>
{/block}
{block name="content"}
<div class="think-box-shadow">
    <table id="oplog" data-url="{:sysuri()}" data-target-search="form.form-search"></table>
</div>
{/block}
{block name='script'}
<script>
    $(function () {
        $('#oplog').layTable({
            even: true, height: 'full',
            sort: {field: 'sort asc,id', type: 'asc'},
            cols: [[
                // {checkbox: true},
                {field: 'sort', title: '排序权重', width: 100, align: 'center', sort: true, templet: '#SortInputTpl'},
                {field: 'id', title: 'ID', align: 'center', width: 100},
                {
                    field: 'photo', title: '图片', width: 100, align: 'center', templet: function (d) {
                        if (!d.photo) return '-';
                        return layui.laytpl('<div class="headimg headimg-ss shadow-inset margin-0" data-tips-image data-tips-hover data-lazy-src="{{d.photo}}"></div>').render(d);
                    }
                },
                {field: 'breed_name', title: '名称'},
                // {field:'weight',title: '体重范围', templet: function(d) {
                //         return d.weight_min+' ~ '+d.weight_max + ' kg';
                //     }
                // },
                {field: 'is_tj', title: '推荐', align: 'center', minWidth: 110, templet: '#StatusSwitchTpl'},
                {field: 'create_at', title: '创建时间',align: 'center'},
                {toolbar: '#toolbar', title: '操作面板', align: 'center',minWidth: 150, fixed: 'right'}
            ]]
        });
        // 数据状态切换操作
        layui.form.on('switch(StatusSwitch)', function (obj) {
            var data = {id: obj.value, is_tj: obj.elem.checked > 0 ? 1 : 0};
            $.form.load("{:url('state')}", data, 'post', function (ret) {
                if (ret.code < 1) $.msg.error(ret.info, 3, function () {
                    $('#oplog').trigger('reload');
                }); else {
                    $('#oplog').trigger('reload')
                }
                return false;
            }, false);
        });
    });

</script>
<!-- 数据状态切换模板 -->
<script type="text/html" id="StatusSwitchTpl">
    <!--{if auth("state")}-->
    <input type="checkbox" value="{{d.id}}" lay-skin="switch" lay-text="是|否" lay-filter="StatusSwitch" {{-d.is_tj>0?'checked':''}}>
    <!--{else}-->
    {{-d.is_tj ? '<b class="color-green">是</b>' : '<b class="color-red">否</b>'}}
    <!--{/if}-->
</script>
<!-- 列表排序权重模板 -->
<script type="text/html" id="SortInputTpl">
    <input type="number" min="0" data-blur-number="0" data-action-blur="{:sysuri()}" data-value="id#{{d.id}};action#sort;sort#{value}" data-loading="false" value="{{d.sort}}" class="layui-input text-center">
</script>
<script type="text/html" id="toolbar">
    <a class="layui-btn layui-btn-sm" data-title="编辑" data-offset="20" data-modal='{:url("edit")}?id={{d.id}}'>编 辑</a>
    <a class="layui-btn layui-btn-sm" data-title="设置数据" data-offset="20" data-iframe='{:url("weight")}?id={{d.id}}'>设 置</a>
    <a data-action='{:url("remove")}' data-value="id#{{d.id}}" data-confirm="确认要删除这条记录吗？" class="layui-btn layui-btn-sm layui-btn-danger">删 除</a>

</script>
{/block}